package com.cw.jeeyt.dao.impl.facade;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.cw.jeeyt.common.utils.StringUtil;
import com.cw.jeeyt.dao.intf.facade.FacadeEnumDao;
import com.cw.jeeyt.dao.mapper.facade.FacadeEnumMapper;
import com.cw.jeeyt.dao.model.facade.FacadeEnumDo;
import com.cw.jeeyt.dao.model.facade.FacadeEnumExample;
import com.cw.jeeyt.dao.model.facade.FacadeEnumKeyDo;
import com.cw.jeeyt.dao.query.facade.FacadeEnumQuery;
import com.cw.lang.common.dao.AbstractBaseDaoImpl;
import com.cw.lang.common.pagehelper.PageHelper;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.mybatis.dto.PageParam;

/**
 * 接口枚举数据库操作接口实现
 *
 * @author chenw
 * @date 2019-10-31 22:35:52
 */
@Repository
public class FacadeEnumDaoImpl extends AbstractBaseDaoImpl<FacadeEnumDo, FacadeEnumMapper> implements FacadeEnumDao {
    /**
     * 分页查询
     *
     * @param facadeEnum 条件
     * @param pageParam 分页参数
     * @return
     */
    @Override
    public PageInfo<FacadeEnumDo> selectPage(FacadeEnumQuery facadeEnum, PageParam pageParam) {
        FacadeEnumExample example = buildExample(facadeEnum);
        return PageHelper.<FacadeEnumDo>startPage(pageParam.getPageNum(), pageParam.getPageSize()).doSelectPageInfo(
            () -> getMapper().selectByExample(example));
    }

    /**
     * 根据key查询接口枚举
     *
     * @param id
     * @return
     */
    @Override
    public FacadeEnumDo selectByKey(Long id) {
        FacadeEnumKeyDo facadeEnumKeyDo = new FacadeEnumKeyDo();
        facadeEnumKeyDo.setId(id);
        return getMapper().selectByPrimaryKey(facadeEnumKeyDo);
    }

    /**
     * 根据key删除接口枚举
     *
     * @param id
     * @return
     */
    @Override
    public int deleteByKey(Long id) {
        FacadeEnumKeyDo facadeEnumKeyDo = new FacadeEnumKeyDo();
        facadeEnumKeyDo.setId(id);
        return getMapper().deleteByPrimaryKey(facadeEnumKeyDo);
    }

    /**
     * 查询接口枚举信息
     *
     * @param facadeEnum 条件
     * @return List<FacadeEnumDo>
     */
    @Override
    public List<FacadeEnumDo> selectByExample(FacadeEnumQuery facadeEnum) {
        return getMapper().selectByExample(buildExample(facadeEnum));
    }

    /**
     * 新增接口枚举信息
     *
     * @param facadeEnum 条件
     * @return int>
     */
    @Override
    public int insertBySelective(FacadeEnumDo facadeEnum) {
        if (facadeEnum == null) {
            return -1;
        }
        return getMapper().insertSelective(facadeEnum);
    }

    /**
     * 修改接口枚举信息
     *
     * @param facadeEnum
     * @return
     */
    @Override
    public int updateBySelective(FacadeEnumDo facadeEnum) {
        if (facadeEnum == null) {
            return -1;
        }
        return getMapper().updateByPrimaryKeySelective(facadeEnum);
    }

    /**
     * 构建接口枚举Example信息
     *
     * @param facadeEnum
     * @return
     */
    public FacadeEnumExample buildExample(FacadeEnumQuery facadeEnum) {
        FacadeEnumExample example = new FacadeEnumExample();
        FacadeEnumExample.Criteria criteria = example.createCriteria();
        if (facadeEnum != null) {
            //添加查询条件
            if (null != facadeEnum.getId()) {
                criteria.andIdEqualTo(facadeEnum.getId());
            }
            if (StringUtil.isNotEmpty(facadeEnum.getEnumCode())) {
                criteria.andEnumCodeEqualTo(facadeEnum.getEnumCode());
            }
            if (StringUtil.isNotEmpty(facadeEnum.getEnumName())) {
                criteria.andEnumNameEqualTo(facadeEnum.getEnumName());
            }
            if (StringUtil.isNotEmpty(facadeEnum.getEnumComment())) {
                criteria.andEnumCommentEqualTo(facadeEnum.getEnumComment());
            }
            if (StringUtil.isNotEmpty(facadeEnum.getEnumItemKey())) {
                criteria.andEnumItemKeyEqualTo(facadeEnum.getEnumItemKey());
            }
            if (StringUtil.isNotEmpty(facadeEnum.getEnumItemCode())) {
                criteria.andEnumItemCodeEqualTo(facadeEnum.getEnumItemCode());
            }
            if (StringUtil.isNotEmpty(facadeEnum.getEnumItemDesc())) {
                criteria.andEnumItemDescEqualTo(facadeEnum.getEnumItemDesc());
            }
            if (null != facadeEnum.getCreateBy()) {
                criteria.andCreateByEqualTo(facadeEnum.getCreateBy());
            }
            if (null != facadeEnum.getCreateDateBegin()) {
                criteria.andCreateDateGreaterThanOrEqualTo(facadeEnum.getCreateDateBegin());
            }
            if (null != facadeEnum.getCreateDateEnd()) {
                criteria.andCreateDateLessThanOrEqualTo(facadeEnum.getCreateDateEnd());
            }
            if (null != facadeEnum.getUpdateBy()) {
                criteria.andUpdateByEqualTo(facadeEnum.getUpdateBy());
            }
            if (null != facadeEnum.getUpdateDateBegin()) {
                criteria.andUpdateDateGreaterThanOrEqualTo(facadeEnum.getUpdateDateBegin());
            }
            if (null != facadeEnum.getUpdateDateEnd()) {
                criteria.andUpdateDateLessThanOrEqualTo(facadeEnum.getUpdateDateEnd());
            }
        }
        return example;
    }
}
